package com.powerunion.datacollection.service;

import java.sql.Connection;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import com.powerunion.datacollection.common.SystemException;
import com.powerunion.datacollection.dao.DaoFactory;
import com.powerunion.datacollection.dao.SmsDao;
import com.powerunion.util.log.LogHelper;

public class SmsManager {
	private static Logger logger = LogHelper.getInstance().getLogger(
			SmsManager.class);
	private SmsDao dao = null;

	public SmsManager() {
		super();
		this.dao = (SmsDao) DaoFactory.getInstance().getDao(SmsDao.class);
	}

	public void saveSMS(Connection conn, String msg, String userCode)
			throws Exception {
		// 参数为空
		if (conn == null) {
			String[] args = { "conn" };
			// 打印错误日志
			StringBuffer msglog = new StringBuffer(
					"empty invoke parameter conn NULL ");
			logger.error(msglog.toString());
			throw new SystemException("error.common.parameter.empty", args);
		}
		// 参数为空
		if (StringUtils.isEmpty(msg)) {
			String[] args = { "msg" };
			// 打印错误日志
			StringBuffer msglog = new StringBuffer(
					"empty invoke parameter msg NULL ");
			logger.error(msglog.toString());
			throw new SystemException("error.common.parameter.empty", args);
		}
		// 参数为空
		if (StringUtils.isEmpty(userCode)) {
			String[] args = { "userCode" };
			// 打印错误日志
			StringBuffer msglog = new StringBuffer(
					"empty invoke parameter userCode NULL ");
			logger.error(msglog.toString());
			throw new SystemException("error.common.parameter.empty", args);
		}
		this.dao.saveSMS(conn, msg, userCode);
	}

	public void saveSMS(String msg, String userCode) throws Exception {
		// 参数为空
		if (StringUtils.isEmpty(msg)) {
			String[] args = { "msg" };
			// 打印错误日志
			StringBuffer msglog = new StringBuffer(
					"empty invoke parameter msg NULL ");
			logger.error(msglog.toString());
			throw new SystemException("error.common.parameter.empty", args);
		}
		// 参数为空
		if (StringUtils.isEmpty(userCode)) {
			String[] args = { "userCode" };
			// 打印错误日志
			StringBuffer msglog = new StringBuffer(
					"empty invoke parameter userCode NULL ");
			logger.error(msglog.toString());
			throw new SystemException("error.common.parameter.empty", args);
		}
		this.dao.saveSMS(msg, userCode);
	}

}
